package com.gujiangbo.netty;

import io.netty.util.HashedWheelTimer;
import io.netty.util.Timeout;
import io.netty.util.TimerTask;

import java.util.concurrent.TimeUnit;

/**
 * @Author: gujiangbo.co
 * @Contact: 646832012@qq.com
 * @Date: 2022/6/2 15:01
 * @Version: 1.0
 * @Description:
 */
public class HashedWheelTimerTest {

    public static void main(String[] args) {
        HashedWheelTimer hashedWheelTimer = new HashedWheelTimer();
        System.out.println("start..");
        hashedWheelTimer.newTimeout(new MyTimer(),5L,TimeUnit.SECONDS);
    }
}

class MyTimer implements TimerTask {

    @Override
    public void run(Timeout timeout) throws Exception {
        System.out.println("MyTimer is start ..");
        //暂停5秒钟线程
        try {
            TimeUnit.MILLISECONDS.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("MyTimer is end ...");
    }
}